package com.ruoyi.web.controller.community.owner;

import java.util.List;
import java.util.Map;

import com.ruoyi.framework.web.domain.server.Sys;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.OwnerGroupMember;
import com.ruoyi.community.service.IOwnerGroupMemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import com.ruoyi.common.core.domain.entity.SysUser;

/**
 * 群组成员列表Controller
 * 
 * @author ruoyi
 * @date 2021-08-05
 */
@RestController
@RequestMapping("/community/owner/member")
public class OwnerGroupMemberController extends BaseController
{
    @Autowired
    private IOwnerGroupMemberService ownerGroupMemberService;

    /**
     * 查询群组成员列表
     */
    @PreAuthorize("@ss.hasPermi('community:member:list')")
    @GetMapping("/list")
//    @GetMapping(value = "/list/{id}")
    public TableDataInfo list(OwnerGroupMember ownerGroupMember, String userName, String phonenumber)
//    public TableDataInfo list(@PathVariable("id") String id)
    {
        startPage();
//        List<Map<String,Object>> listMap = ownerGroupMemberService.selectOwnerGroupMemberList(ownerGroupMember);
        List<Map<String,Object>> listMap = ownerGroupMemberService.selectOwnerGroupMemberList(ownerGroupMember.getGroupId(), userName, phonenumber);
//        List<OwnerGroupMember> list = map.ownerGroupMember;
//        List<SysUser> listUser = map.sysUsers;
        return getDataTable(listMap);
    }

    @GetMapping("/ifInGroup")
    public boolean ifInGroup(String userId, String groupId)
    {
        return ownerGroupMemberService.isInGroup(userId, groupId);
    }
//
//    /**
//     * 导出群组成员列表列表
//     */
//    @PreAuthorize("@ss.hasPermi('community:member:export')")
//    @Log(title = "群组成员列表", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(OwnerGroupMember ownerGroupMember)
//    {
//        List<OwnerGroupMember> list = ownerGroupMemberService.selectOwnerGroupMemberList(ownerGroupMember).ownerGroupMember;
//        ExcelUtil<OwnerGroupMember> util = new ExcelUtil<OwnerGroupMember>(OwnerGroupMember.class);
//        return util.exportExcel(list, "群组成员列表数据");
//    }
//
//    /**
//     * 获取群组成员列表详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('community:member:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") String id)
//    {
//        return AjaxResult.success(ownerGroupMemberService.selectOwnerGroupMemberById(id));
//    }

    /**
     * 新增群组成员列表
     */
    @PreAuthorize("@ss.hasPermi('community:member:add')")
    @Log(title = "群组成员列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnerGroupMember ownerGroupMember)
    {
        return toAjax(ownerGroupMemberService.insertOwnerGroupMember(ownerGroupMember));
    }

//    /**
//     * 修改群组成员列表
//     */
//    @PreAuthorize("@ss.hasPermi('community:member:edit')")
//    @Log(title = "群组成员列表", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody OwnerGroupMember ownerGroupMember)
//    {
//        return toAjax(ownerGroupMemberService.updateOwnerGroupMember(ownerGroupMember));
//    }
//
    /**
     * 删除群组成员列表
     */
    @PreAuthorize("@ss.hasPermi('community:member:remove')")
    @Log(title = "群组成员列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ownerGroupMemberService.deleteOwnerGroupMemberByIds(ids));
    }
}
